import com.sun.org.apache.xpath.internal.operations.Bool;
import net.egork.utils.Solver;
import net.egork.utils.io.InputReader;

import java.io.PrintWriter;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Vector;

public class CTREE implements Solver {
    int n;
    Vector<Integer> adj[];
    Vector<Integer> child[];
    int ans[][];
    int color[];
    int childColor[][] = {{1, 2}, {0, 2}, {0, 1}};

    public void solve(int testNumber, InputReader in, PrintWriter out) {

        n = in.readInt();
        adj = new Vector[n];
        for (int i = 0; i < n; ++i)
            adj[i] = new Vector<Integer>();
        for (int i = 0; i < n - 1; ++i) {
            int u = in.readInt() - 1;
            int v = in.readInt() - 1;
            adj[u].add(v);
            adj[v].add(u);
        }

        bfsTree();

        ans = new int[n][3];
        int res = Math.min(minSum(0, 0), Math.min(minSum(0, 1), minSum(0, 2)));
        out.println(res);

        color = new int[n];
        trace(0, -1);
        for (int i = 0; i < n; ++i)
            out.println(color[i]);
    }

    private void trace(int u, int parentColor) {
        int min = Integer.MAX_VALUE;
        for (int c = 0; c < 3; ++c)
            if (c != parentColor)
                min = Math.min(min, ans[u][c]);
        for (int c = 0; c < 3; ++c) {
            if (c != parentColor && min == ans[u][c]) {
                color[u] = c + 1;
                for (int v : child[u])
                    trace(v, c);
                break;
            }
        }
    }

    private void bfsTree() {
        child = new Vector[n];
        for (int i = 0; i < n; ++i)
            child[i] = new Vector<Integer>();

        boolean visited[] = new boolean[n];
        Arrays.fill(visited, false);

        Queue<Integer> q = new LinkedList<Integer>();
        q.add(0);
        while (!q.isEmpty()) {
            int u = q.poll();
            visited[u] = true;
            for (int v : adj[u])
                if (!visited[v]) {
                    child[u].add(v);
                    q.add(v);
                }
        }
    }

    private int minSum(int u, int myColor) {
        if (ans[u][myColor] > 0)
            return ans[u][myColor];
        int res;
        if (child[u].size() == 0) {
            res = myColor + 1;
        } else {
            int sum = 0;
            for (int v : child[u])
                sum += Math.min(minSum(v, childColor[myColor][0]),
                        minSum(v, childColor[myColor][1]));
            res = myColor + 1 + sum;
        }
        ans[u][myColor] = res;
        return res;
    }
}

